#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QProcess>
#include <QFileDialog>
#include <QListWidget>
#include <QVBoxLayout>
#include <QTimer>
#include <QThread>
#include <QCheckBox>
#include "file_scanner.h"
#include "custom_tree_widget.h"
#include "custom_progress_bar.h"
#include "TreeMap.h"
#include "custom_widget.h"
#include "show_followed_unit.h"

QT_BEGIN_NAMESPACE
namespace Ui { class DiskusageAnalyser; }
QT_END_NAMESPACE

extern QVector<QString> disks;
extern int CustomIndex;
extern int MultiIndex;
extern QSharedPointer<MTree> Mroot;
extern Trie Troot;
extern QThread *scanThread;
extern bool isDrawingTree;
extern int TreemapWidth, TreemapHeight;

class MainWindow : public QMainWindow
{
    Q_OBJECT

private:
    Ui::DiskusageAnalyser* ui;

public:

    MainWindow(QWidget* parent = nullptr);
    ~MainWindow();

public:
    void ComboRootPathInit();
    void DrawTree(QTreeWidgetItem* parentItem, QSharedPointer<MTree> currentNode);
    void TreeSort_Down(int index);
    void TreeSort_Up(int index);

private slots:
    void on_ScanStart_clicked();
    void on_drawTreemap_clicked();
    void onItemExpanded(QTreeWidgetItem* item);
    void onItemCollapsed(QTreeWidgetItem* item);
    void onRectangleClicked(QSharedPointer<MTree> root);
    void setupScanThread();
    void setupTimer(QTimer *timer);
    void setupConnections(QTimer *timer);
    void setupTrie();
    void drawTreeAndSort();
    void drawTreeMap(QSharedPointer<MTree> root);

};

QVector<QString> parseMultiSelection(const QString& multiSelection);
void sortAllItems_Down(QTreeWidgetItem* item, int index);
void sortAllItems_Up(QTreeWidgetItem* item, int index);
void TrieInsert(QSharedPointer<MTree> father);
void TrieInsertUseSuffix(QSharedPointer<MTree> father);

#endif // MAINWINDOW_H
